<template>
  <div class="JNPF-common-layout">
    <div class="JNPF-common-layout-center">
      <el-row class="JNPF-common-search-box" :gutter="16">
        <el-form @submit.native.prevent label-width="90px" label-position="left">
          <el-col :span="8">
            <el-form-item
                label="客户名称"
              >
                <el-select
                  :disabled="$store.state.user.fsiteLevel == 3"
                  v-model="listQuery.fsiteNo"
                  clearable
                  filterable
                  class="filter-item"
                  placeholder="请选择客户名称"
                >
                  <el-option
                    v-for="item in getListfsiteNo"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="存放地点">
              <el-select
                  style="display: inline-block"
                  clearable
                  filterable
                  v-model="listQuery.fpointNo"
                  class="filter-item"
                  placeholder="请选择存放地点"
                >
                  <el-option
                    v-for="item in getListfpointNoArea"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
            </el-form-item>
          </el-col>
          <template v-if="showAll">
            <el-col :span="8">
            <el-form-item label="固定资产码">
              <el-input
                v-model="listQuery.fmacno"
                clearable
                class="filter-item"
                placeholder="请输入固定资产码"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="序列号">
              <el-input
                v-model="listQuery.fequipmentbarcode"
                clearable
                class="filter-item"
                placeholder="请输入序列号"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="存储分类">
            <el-select
              style="display: inline-block"
              clearable
              filterable
              v-model="listQuery.fstorageflag"
              class="filter-item"
              placeholder="请选择存储分类"
            >
              <el-option
                v-for="item in getListfstorageflag"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          </el-col>
          <el-col :span="8">
             <el-form-item label="设备状态">
              <el-select
                style="display: inline-block"
                clearable
                filterable
                v-model="listQuery.fstate"
                class="filter-item"
                placeholder="请选择设备状态"
              >
                <el-option
                  v-for="item in getListfstate"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          </template>
          <el-col :span="8">
            <el-form-item>
        <el-button
        type="primary"
          @click="handleFilter"
          >查找</el-button
        >
        <el-button
         type="success"
          @click="handleCreate"
          >添加</el-button
        >
        <el-button
        type="info"
          @click="handleUpload"
          >导入</el-button
        >
        <el-button type="text" icon="el-icon-arrow-down" @click="showAll=true"
                v-if="!showAll">展开</el-button>
              <el-button type="text" icon="el-icon-arrow-up" @click="showAll=false" v-else>
                收起</el-button>
      </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="JNPF-common-layout-main JNPF-flex-main">
       <!-- 查询结果 -->
    <JNPF-table
      v-loading="listLoading"
      :data="list"
    >
      <el-table-column align="center" :width="buttonColor.operationTwo" label="操作" class-name="small-padding">
        <template slot-scope="scope">
          <el-button type="text" @click="handleUpdate(scope.row)">编辑</el-button>
          <el-button type="text" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
      <el-table-column
        :width="buttonColor.line"
        :index="indexMethod"
        align="center"
        label="序号"
        type="index"
      />
      <el-table-column
        :formatter="formatfpointNo"
        align="left"
        label="存放地点"
        prop="fpointNo"
      />
      <el-table-column
        :width="buttonColor.billno"
        align="left"
        label="序列号"
        prop="fequipmentbarcode"
      />
      <el-table-column :width="buttonColor.billno" align="left" label="固定资产码" prop="fmacno" />
      <el-table-column :width="buttonColor.name" align="left" label="储物仓名称" prop="fequipmenttag" />
      <el-table-column
        :formatter="formatfstorageflag"
        align="left"
        label="存储分类"
        prop="fstorageflag"
      />
      <el-table-column align="left" :width="buttonColor.state" label="设备状态" prop="fstate">
        <template slot-scope="scope">
          <span :style="{ color: buttonColor.itemconfirmed }" v-if="scope.row.fstate === 1">{{ scope.row.fstate |
              statusFilter
          }}</span>
          <span :style="{ color: buttonColor.itemisconfirmed }" v-else-if="scope.row.fstate === 2">{{ scope.row.fstate |
              statusFilter
          }}</span>
          <span :style="{ color: buttonColor.iteminvalid }" v-else>{{ scope.row.fstate | statusFilter }}</span>
        </template>
      </el-table-column>
    </JNPF-table>
    <paginations
    :total="total"
      :page.sync="listQuery.currentPage"
      :limit.sync="listQuery.pageSize"
      />
      </div>
    </div>
    <!-- 添加或修改对话框 -->
    <el-dialog
      :close-on-click-modal="false"
      :visible.sync="dialogFormVisible"
      width="90%"
      top="10px"
      :title="textMap[dialogStatus]"
    >
    <el-row class="JNPF-common-search-box" :gutter="16">
        <el-form @submit.native.prevent label-width="100px" ref="dataForm" :model="dataForm" :rules="rules">
         <el-col :span="8">
          <el-form-item  label="设备序列号" prop="fequipmentbarcode">
              <el-input
                v-if="dialogStatus == 'create'"
                v-model="dataForm.fequipmentbarcode"
              />
              <el-input v-else disabled v-model="dataForm.fequipmentbarcode" />
            </el-form-item>
         </el-col>
         <el-col :span="8">
           <el-form-item label="固定资产码" prop="fmacno">
              <el-input v-model="dataForm.fmacno" />
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item  label="设备状态" prop="fstate">
              <el-select
                clearable
                filterable
                v-model="dataForm.fstate"
                class="filter-item"
                placeholder="请选择设备状态"
              >
                <el-option
                  v-for="item in getListfstate"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item  label="设备名称" prop="fequipmenttag">
              <el-input
              v-if="dialogStatus == 'create'"
                  v-model="dataForm.feuipmentidname"
                >
                <el-button slot="append" icon="el-icon-search" @click="searchDialogEequipmentInfo"></el-button>
                </el-input>
                <el-input
                v-else
                  disabled
                  v-model="dataForm.fequipmenttag"
                  style="display: inline-block"
                />
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="存放地点" prop="fpointNo">
              <el-select
                  style="display: inline-block"
                  clearable
                  filterable
                  v-model="dataForm.fpointNo"
                  class="filter-item"
                  placeholder="请选择存放地点"
                >
                  <el-option
                    v-for="item in getListfpointNo"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="存放位置" prop="fpointSize">
              <el-input v-model="dataForm.fpointSize" />
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item  label="存储分类" prop="fstorageflag">
              <el-select
                v-if="dialogStatus == 'create'"
                clearable
                filterable
                v-model="dataForm.fstorageflag"
                class="filter-item"
                placeholder="请选择存储分类"
              >
                <el-option
                  v-for="item in getListfstorageflag"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
              <el-select
                v-else
                disabled
                clearable
                filterable
                v-model="dataForm.fstorageflag"
                class="filter-item"
                placeholder="请选择存储分类"
              >
                <el-option
                  v-for="item in getListfstorageflag"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="存储个数" prop="fnum">
              <el-input v-model="dataForm.fnum" />
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="承受重量" prop="fweight">
              <el-input v-model="dataForm.fweight" />
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="RFID-IP" prop="frfidip">
              <el-input v-model="dataForm.frfidip" />
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="RFID-PORT" prop="frfidport">
              <el-input v-model="dataForm.frfidport" />
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item  label="RFID-LINE" prop="frfidid">
              <el-input v-model="dataForm.frfidid" />
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="控制器类型" prop="fiptype">
              <el-select
                clearable
                filterable
                v-model="dataForm.fiptype"
                class="filter-item"
                placeholder="请选择控制器类型"
              >
                <el-option
                  v-for="item in getListfiptype"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="控制器-IP" prop="fip">
              <el-input v-model="dataForm.fip" />
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="控制器端口" prop="fport">
              <el-input v-model="dataForm.fport" />
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="开门指令" prop="fon">
              <el-input v-model="dataForm.fon" />
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="关门指令" prop="foff">
              <el-input v-model="dataForm.foff" />
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="门锁位数" prop="fcloseflag">
              <el-input v-model="dataForm.fcloseflag" />
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="温控指令" prop="fairport">
              <el-input v-model="dataForm.fairport" />
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="温控-IP" prop="fairip">
              <el-input v-model="dataForm.fairip" />
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="询问状态" prop="flamp5">
              <el-input v-model="dataForm.flamp5" />
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="报警指令" prop="fnoorder">
              <el-input v-model="dataForm.fnoorder" />
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="指示灯开" prop="flamp3">
              <el-input v-model="dataForm.flamp3" />
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="状态灯开" prop="flamp1">
              <el-input v-model="dataForm.flamp1" />
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="达标指令" prop="fyesorder">
              <el-input v-model="dataForm.fyesorder" />
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="指示灯关" prop="flamp4">
              <el-input v-model="dataForm.flamp4" />
            </el-form-item>
         </el-col>
         <el-col :span="8">
          <el-form-item label="状态灯关" prop="flamp2">
              <el-input v-model="dataForm.flamp2" />
            </el-form-item>
         </el-col>
        </el-form>
      </el-row>
      
      <span  slot="footer" class="dialog-footer">
        <el-button
          @click="dialogFormVisible = false"
          type="info"
          >取消</el-button
        >
        <el-button
        type="primary"
          v-if="dialogStatus == 'create'"
          @click="createData"
          >确定</el-button
        >
        <el-button
        type="primary"
          v-else
          @click="updateData"
          >确定</el-button
        >
      </span >
    </el-dialog>
    <!-- 导入弹窗 -->
    <el-dialog width="40%" title="仓库报损" :close-on-click-modal="false" :visible.sync="uploadVisible">
      <div style="display: flex;flex-direction: column;align-items: center">
         <el-upload
              class="upload-demo"
              ref="upload"
          action
          drag
          :auto-upload="true"
          :http-request="fileUpload"
          :on-change="handleChange"
          >
              <i class="el-icon-upload"></i>
              <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
            </el-upload>
      </div>
    </el-dialog>
    <equipmentInfoDialog
      :equipmentInfoVisible.sync="equipmentInfoVisible"
      :tableColor="tableColor"
      @equipmentInfoDialog="equipmentInfoDialogValue"
    />
  </div>
</template>

<script>
import {
  listtsWarehouse,
  createtsWarehouse,
  updatetsWarehouse,
  deletetsWarehouse,
  uploadPath,
} from "@/api/tsWarehouse";
import {
  getListArea,
  getFequipmentbarcode,
  fsiteOptionsByLevel,
  uploadPathHy,
  getPointOptions,
} from "@/api/area";
import { getToken } from "@/utils/auth";
import Pagination from "@/components/Pagination";
import EquipmentInfoDialog from "@/components/EquipmentInfoDialog";
import {
  tableColor,
  titleColor,
  exportColor,
  buttonColor,
} from "@/filters/index";
import moment from "moment";
import { getApiUrl} from "@/utils/request";
import request from '@/utils/request'
import LabDialog from "@/components/LabDialog";

const statusMap = {
  1: '已启用',
  2: '闲置中',
  8: '已报废',
}

export default {
  name: "tsWarehouse",
  components: { Pagination, EquipmentInfoDialog, LabDialog },
  filters: {
    statusFilter(type) {
      return statusMap[type]
    }
  },
  data() {
    return {
      labFlag: null,
      getListfpointNoAll: [],
      searchVisiblelab: false,
      labDialogFsiteNo: null,
      getListfpointNo: [],
      showAll:false,
      getListfpointNoArea: [],
      downUrl: null,
      uploadVisible: false,
      uploadPathHy,
      uploadPath,
      getListfsiteNo: [],
      buttonColor: buttonColor,
      aa: 5,
      equipmentInfoVisible: false,
      getListfstorageflag: [],
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        feuipmentid: undefined,
        fequipmentbarcode: undefined,
        fequipmenttag: undefined,
        fstorageflag: undefined,
        fimage: undefined,
        fip: undefined,
        fport: undefined,
        fon: undefined,
        foff: undefined,
        frfidip: undefined,
        frfidport: undefined,
        frfidid: undefined,
        fairip: undefined,
        fairport: undefined,
        fstate: undefined,
        fupddate: undefined,
        foperator: undefined,
        fpointNo: undefined,
        fmacno: undefined,
        fiptype: undefined,
        fcloseflag: undefined,
        flamp5: undefined,
        sort: "create_time",
        order: "desc",
        fsiteNo: undefined,
      },
      dataForm: {
        feuipmentid: undefined,
        fequipmentbarcode: undefined,
        fequipmenttag: undefined,
        fstorageflag: undefined,
        fimage: undefined,
        fip: undefined,
        fport: undefined,
        fon: undefined,
        foff: undefined,
        frfidip: undefined,
        frfidport: undefined,
        frfidid: undefined,
        fairip: undefined,
        fairport: undefined,
        fstate: undefined,
        fupddate: undefined,
        foperator: undefined,
        id: undefined,
        fspec: undefined,
        fequipmenttype: undefined,
        flamp1: undefined,
        flamp2: undefined,
        flamp3: undefined,
        flamp4: undefined,
        fmacno: undefined,
        fnoorder: undefined,
        fyesorder: undefined,
        feuipmentidname:"",
        fsiteNo: undefined,
        fpointNo: undefined,
        fpointSize: undefined,
        fnum: undefined,
        fweight: undefined,
        fiptype: undefined,
        fcloseflag: undefined,
        flamp5: undefined,
      },
      file:undefined,
      tableColor,
      titleColor,
      exportColor,
      dialogFormVisible: false,
      dialogStatus: "",
      textMap: {
        update: "编辑",
        create: "创建",
      },
      rules: {
        fsiteNo: [{ required: true, message: "客户名称不能为空" }],
        feuipmentid: [{ required: true, message: "设备编号不能为空" }],
        fequipmentbarcode: [{ required: true, message: "序列号不能为空" }],
        fequipmenttag: [{ required: true, message: "储物仓名称不能为空" }],
        fstorageflag: [{ required: true, message: "存储分类不能为空" }],
        frfidid: [
          { required: true, message: "RFID-LINE不能为空" },
        ],
        fstate: [
          { type: "number", message: "设备状态必须为数字值", trigger: "blur" },
        ],
      },
      getListfstate: [
        { value: 1, label: "已启用" },
        { value: 2, label: "闲置中" },
        { value: 8, label: "已报废" },
      ],
      getListfiptype: [
        { value: 1, label: "8路网口" },
        { value: 2, label: "4路485" },
      ],
    };
  },
  created() {
    this.downUrl = getApiUrl() + "xlsx/2-1储物仓资料.xlsx";
    getListArea({ flag: 28 })
      .then((response) => {
        this.getListfstorageflag = response.data.data.list;
      })
      .catch(() => {
        this.getListfstorageflag = [];
      });
    fsiteOptionsByLevel(3)
      .then((response) => {
        this.getListfsiteNo = response.data.data.list;
      })
      .catch(() => {
        this.getListfsiteNo = [];
      });
    if (this.$store.state.user.fsiteLevel == 3) {
      this.listQuery.fsiteNo = this.$store.state.user.fsiteNo;
      // 存放地点
      getListArea({ flag: 10, arg1: this.$store.state.user.fsiteNo })
        .then((response) => {
          this.getListfpointNo = response.data.data.list;
          this.getListfpointNoArea = response.data.data.list;
        })
        .catch(() => {
          this.getListfpointNo = [];
          this.getListfpointNoArea = [];
        });
        // 存放地点
        getPointOptions(this.$store.state.user.fsiteNo)
          .then((response) => {
            this.getListfpointNoAll = response.data.data.list;
          })
          .catch(() => {
            this.getListfpointNoAll = [];
          });
    }else{
      // 存放地点
      getPointOptions()
        .then((response) => {
          this.getListfpointNoAll = response.data.data.list;
        })
        .catch(() => {
          this.getListfpointNoAll = [];
        });
    }
    this.getList();

  },
  computed: {
    headers() {
      return {
        Authorization: getToken(),
      };
    },
  },
  methods: {
    uploadFileSuccess: function (response) {
      this.uploadVisible = false;
      this.$notify.success({
        title: "导入",
        dangerouslyUseHTMLString: true,
        message: response.data,
      });
    },
    handleUpload() {
      this.uploadVisible = true;
    },
    datetimeFormat(row, column) {
      const date = row[column.property];
      if (date === undefined || date === null) {
        return "";
      }
      return moment(date).format("YYYY-MM-DD HH:mm:ss");
    },
    formdata2: function (fequipmentbarcode) {
      return { ftype: "8", fequipmentbarcode: fequipmentbarcode };
    },
    handleAvatarSuccess(res, file) {
      this.dataForm.fimage = res.data;
      const time = new Date().getTime();
      this.dataForm.fimage = `${this.dataForm.fimage}?time=${time}`;
    },
    beforeAvatarUpload(file) {
      const isLt2M = file.size / 1024 / 1024 < 2;
      if (!isLt2M) {
        this.$message.error("上传图片大小不能超过 2MB!");
      }
      return isLt2M;
    },

    changeFsiteNo(data) {
      this.listQuery.fpointNo = "";
      this.getListfpointNoArea = [];
      if (data) {
        // 存放地点
        getListArea({ flag: 10, arg1: data })
          .then((response) => {
            this.getListfpointNoArea = response.data.data.list;
          })
          .catch(() => {
            this.getListfpointNoArea = [];
          });
      }
    },

    changeFsiteNoAdd(data) {
      this.dataForm.fpointNo = "";
      this.getListfpointNo = [];
      if (data) {
        // 存放地点
        getListArea({ flag: 10, arg1: data })
          .then((response) => {
            this.getListfpointNo = response.data.data.list;
          })
          .catch(() => {
            this.getListfpointNo = [];
          });
      }
    },

    // 搜索地点弹出框
    searchDialoglab(value) {
      this.labFlag = value;
      if (value === "add") {
        this.labDialogFsiteNo = this.dataForm.fsiteNo;
      } else {
        this.labDialogFsiteNo = this.listQuery.fsiteNo;
      }
      this.searchVisiblelab = true;
    },

    // 地点弹出框返回值
    labDialogValue(value) {
      if (this.labFlag === "add") {
        this.dataForm.fpointNo = value.lab.fpointNo;
      } else {
        this.listQuery.fpointNo = value.lab.fpointNo;
      }
    },

    // 存放地点
    formatfpointNo: function (row, column) {
      if (this.getListfpointNoAll) {
        for (let i = 0; i < this.getListfpointNoAll.length; i++) {
          if (row.fpointNo === this.getListfpointNoAll[i].value) {
            return this.getListfpointNoAll[i].label;
          }
        }
        return "";
      } else {
        return "";
      }
    },

    // 客户名称
    formatfsiteNo: function (row, column) {
      if (this.getListfsiteNo) {
        for (let i = 0; i < this.getListfsiteNo.length; i++) {
          if (row.fsiteNo === this.getListfsiteNo[i].value) {
            return this.getListfsiteNo[i].label;
          }
        }
        return "";
      } else {
        return "";
      }
    },
    // 存储分类
    formatfstorageflag: function (row, column) {
      if (this.getListfstorageflag) {
        for (let i = 0; i < this.getListfstorageflag.length; i++) {
          if (row.fstorageflag == this.getListfstorageflag[i].value) {
            return this.getListfstorageflag[i].label;
          }
        }
        return "";
      } else {
        return "";
      }
    },
    // 状态
    formatfstate: function (row, column) {
      if (this.getListfstate) {
        for (let i = 0; i < this.getListfstate.length; i++) {
          if (row.fstate == this.getListfstate[i].value) {
            return this.getListfstate[i].label;
          }
        }
        return "";
      } else {
        return "";
      }
    },
    // 设备信息弹出框
    searchDialogEequipmentInfo() {
      this.equipmentInfoVisible = true;
    },

    // 设备信息弹出框
    equipmentInfoDialogValue(value) {
      this.dataForm.feuipmentid = value.info.feuipmentid;
      this.dataForm.fequipmenttag = value.info.fequipmentname;
      this.dataForm.fequipmenttype = value.info.fequipmenttype;
      this.dataForm.fspec = value.info.fspec;
      this.dataForm.fequipmenttag=value.info.feuipmentid;
      this.dataForm.feuipmentidname=value.info.fequipmentname;
      getFequipmentbarcode({ feuipmentid: value.info.feuipmentid })
        .then((response) => {
          if (response) {
            this.dataForm.fequipmentbarcode = response.data.data;
          }
        })
        .catch(() => {
          this.dataForm.fequipmentbarcode = "";
        });
    },
    getList() {
      this.listLoading = true;
      if (this.listQuery.fequipmentbarcode == "") {
        this.listQuery.fequipmentbarcode = null;
      }
      listtsWarehouse(this.listQuery)
        .then((response) => {
          this.list = response.data.data.list;
          this.total = response.data.data.total;
          this.listLoading = false;
        })
        .catch(() => {
          this.list = [];
          this.total = 0;
          this.listLoading = false;
        });
    },
    handleFilter() {
      this.listQuery.page = 1;
      this.getList();
    },
    resetForm() {
      this.dataForm = {
        feuipmentid: undefined,
        fequipmentbarcode: undefined,
        fequipmenttag: undefined,
        fstorageflag: undefined,
        fimage: undefined,
        fip: undefined,
        fport: undefined,
        fon: undefined,
        foff: undefined,
        frfidip: undefined,
        frfidport: undefined,
        frfidid: undefined,
        fairip: undefined,
        fairport: undefined,
        fstate: undefined,
        fupddate: undefined,
        foperator: undefined,
        id: undefined,
        flamp1: undefined,
        flamp2: undefined,
        flamp3: undefined,
        flamp4: undefined,
        fmacno: undefined,
        fnoorder: undefined,
        fyesorder: undefined,
        fpointNo: undefined,
        fpointSize: undefined,
        fnum: undefined,
        fweight: undefined,
        fiptype: undefined,
        fcloseflag: undefined,
        flamp5: undefined,
      };
    },
    handleCreate() {
      this.resetForm();
      this.dialogStatus = "create";
      if (this.getListfstorageflag.length > 0) {
        this.dataForm.fstorageflag = this.getListfstorageflag[0].value;
      }
      if (this.$store.state.user.fsiteLevel == 3) {
        this.dataForm.fsiteNo = this.$store.state.user.fsiteNo;
      } else {
        this.getListfpointNo = [];
      }

      this.dataForm.fstate = 1;
      this.dialogFormVisible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].clearValidate();
      });
    },
    createData() {
      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
          createtsWarehouse(this.dataForm)
            .then((response) => {
              this.list.unshift(response.data.data);
              this.dialogFormVisible = false;
              this.$notify.success({
                title: "成功",
                message: "添加储物仓资料成功",
              });
            })
            .catch((response) => {
              this.$notify.error({
                title: "失败",
                message: response.data.data,
              });
            });
        }
      });
    },
    handleUpdate(row) {
      this.dataForm = Object.assign({}, row);
      this.dialogStatus = "update";
      this.dialogFormVisible = true;
      if (this.$store.state.user.fsiteLevel != 3) {
        // 存放地点
        getListArea({ flag: 10, arg1: row.fsiteNo })
          .then((response) => {
            this.getListfpointNo = response.data.data.list;
          })
          .catch(() => {
            this.getListfpointNo = [];
          });
      }
      this.$nextTick(() => {
        this.$refs["dataForm"].clearValidate();
      });
    },
    updateData() {
      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
          (this.dataForm.fupddate = new Date()),
            (this.dataForm.foperator = this.$store.state.user.id.toString()),
            updatetsWarehouse(this.dataForm, this.$route.query.id)
              .then(() => {
                for (const v of this.list) {
                  if (v.fequipmentbarcode === this.dataForm.fequipmentbarcode) {
                    const index = this.list.indexOf(v);
                    this.list.splice(index, 1, this.dataForm);
                    break;
                  }
                }
                this.dialogFormVisible = false;
                this.$notify.success({
                  title: "成功",
                  message: "更新储物仓资料成功",
                });
              })
              .catch((response) => {
                this.$notify.error({
                  title: "失败",
                  message: response.data.data,
                });
              });
        }
      });
    },
    handleDelete(row) {
      this.$confirm("是否要删除储物仓资料", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          deletetsWarehouse(row)
            .then((response) => {
              this.$notify.success({
                title: "成功",
                message: "删除储物仓资料成功",
              });
              const index = this.list.indexOf(row);
              this.list.splice(index, 1);
            })
            .catch((response) => {
              this.$notify.error({
                title: "失败",
                message: response.data.data,
              });
            });
        })
        .catch(() => {});
    },
    indexMethod(index) {
      index = index + 1;
      return index;
    },
    //
    // 文件格式判断(xlsx|xls|XLSX|XLS)
    handleChange(file,) {
      // if (!/\.(txt)$/.test(file.name)) {
      //   this.$message({
      //     type: "error",
      //     message: "上传文件只能为txt文件!",
      //   });
      // }
      // else
      // {
      //   this.issubmit=true;
      // }
      this.file = file.raw; // 手动上传需要保存 file.raw
    },
    fileUpload() {
      updateFile(this.file)
        .then((res) => {
          this.$alert(res.msg, {
            confirmButtonText: "确定",
          });
          this.fileList = [];
          this.loading = false;
        })
        .catch((res) => {
          this.$message({
            type: "error",
            message: res,
          });
          this.fileList = [];
          this.loading = false;
        });
    },
  },
};
function updateFile(file) {
  let param = new FormData();
  param.append("file", file); 
  return request({
    url: `/files/upload`,
    method: "post",
    headers: { "Content-Type": "multipart/form-data" },
    data: param,
  });
}
</script>